package com.yanfan.mq.redischannel.listen;

import com.yanfan.common.constant.YanfanConstant;
import com.yanfan.common.core.mq.DeviceTestReportBo;
import com.yanfan.mq.redischannel.consumer.DeviceTestConsumer;
import com.yanfan.mq.redischannel.queue.DeviceTestQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author bill
 */
@Component
@Slf4j
public class DeviceTestListen {

    @Resource
    private DeviceTestConsumer deviceTestConsumer;

    @Async(YanfanConstant.TASK.DEVICE_TEST_TASK)
    public void listen() {
        while (true) {
            try {
                DeviceTestReportBo take = DeviceTestQueue.take();

                deviceTestConsumer.consume(take);
            } catch (Exception e) {
                log.error("=>emq数据转发异常");
            }
        }
    }
}
